<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
</head>

<body>

    <h2>JavaScript 类</h2>

    <p>如何使用 JavaScript 类</p>

    <p id="demo"></p>

    <script>
        class Runoob {
            constructor(name, url) {
                this.name = name;
                this.url = url;
            }
        }
        // 定义好类后，我们就可以使用 new 关键字来创建对象：
        // 创建对象时会自动调用构造函数方法 constructor()。
        let site = new Runoob("菜鸟教程", "https://www.runoob.com");
        document.getElementById("demo").innerHTML =
            site.name + "：" + site.url;

        // 未命名/匿名类
        let Runoob2 = class {
            constructor(name, url) {
                this.name = name;
                this.url = url;
            }
        };
        console.log(Runoob2.name);
        // output: "Runoob2"

        // 命名类
        let Runoob3 = class Runoob4 {
            constructor(name, url) {
                this.name = name;
                this.url = url;
            }
        };
        console.log(Runoob3.name);
        // 输出: "Runoob4"
    </script>

</body>

</html>